package com.jiazhong.basic.shuxin.thread;

public class DemoD {

    private int count = 0;

//    public synchronized void changeCount() {
//        String currentThreadName = Thread.currentThread().getName();
//        System.out.println(currentThreadName + "准备执行对count自增的操作,当前count:" + count);
//        this.count = this.count + 1;
//        System.out.println(currentThreadName + "结束对count自增的操作,当前count:" + count);
//    }

    public void changeCount() {
        String currentThreadName = Thread.currentThread().getName();
        synchronized (this){
            System.out.println(currentThreadName + "准备执行对count自增的操作,当前count:" + count);
            this.count = this.count + 1;
            System.out.println(currentThreadName + "结束对count自增的操作,当前count:" + count);
        }
    }
}
